package com.city.ajax.special;

import com.city.domain.special.HpImpOrganization;
import com.city.domain.supervise.ImpLocation;
import com.city.domain.supervise.PubKeyPerson;
import com.city.helper.FormatHelper;
import com.city.repository.pub.PubKeyPersonRepository;
import com.city.service.pub.impl.PubKeyTrajectoryServiceImpl;
import com.city.service.special.HpImpOrganizationService;
import com.city.service.supervise.ImpLocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName ImpPosAjax
 * @Author 何平
 * @Description  返回分析数据信息
 * @Date 9:28 2018/7/29
 **/
@Controller
@RequestMapping("/ajax/ImpPosAjax")
public class ImpPosAjax {
    private static  int num = 0;
    @Autowired
    private HpImpOrganizationService service;

    @Autowired
    private PubKeyPersonRepository pubKeyPersonRepository;

    @Autowired
    private PubKeyTrajectoryServiceImpl pubKeyTrajectoryService;

    @Autowired
    private ImpLocationService locationService;
    /**
     * @Author 何平 
     * @Description  返回重点组织位置信息
     * @Date 9:35 2018/7/29
     * @Param []
     * @return java.util.List<com.city.domain.special.HpImpOrganization>
     **/
    @RequestMapping("/find_all")
    @ResponseBody
    public List<HpImpOrganization> find_all(){

        return service.findAll();
    }

    /**
     * @Author 何平
     * @Description //TODO 返回某人的轨迹
     * @Date 18:49 2018/8/22
     * @Param []
     * @return java.util.List<com.city.domain.pub.PubKeyTrajectory>
     **/
    @RequestMapping("/get_trajectory")
    @ResponseBody
    public Map<String,Object> get_trajectory(@RequestParam(value = "id") String id,@RequestParam(value = "username") String username){
        Map<String,Object> map = new HashMap<>();
        if(!"".equals(id)){
            map.put("trajectory",pubKeyTrajectoryService.getAll("pub_key_person",id));
            map.put("person",pubKeyPersonRepository.findById(Integer.parseInt(id)));
        }else{
            PubKeyPerson person = pubKeyPersonRepository.findByName(username);
            map.put("person",person);
            map.put("trajectory",pubKeyTrajectoryService.getAll("pub_key_person",person.getId().toString()));
        }

        return map;
    }


    /**
     * @Author 何平
     * @Description //TODO 所有重点地点信息
     * @Date 18:20 2018/8/23
     * @Param []
     * @return java.util.Map<java.lang.String,java.lang.Object>
     **/
    @RequestMapping("/imp_location")
    @ResponseBody
    public Map<String,Object> imp_location(@RequestParam(value = "loname") String loname){
        Map<String,Object> map = new HashMap<>();
        if("".equals(loname)){
            List<ImpLocation> locations = locationService.getAll();
            map.put("locations",locations);
        }else{
            map.put("locations",locationService.getByLoname(loname));
        }
        return map;
    }

    /**
     * @Author 何平
     * @Description  返回岗位评价圆中的数据
     * @Date 18:27 2018/7/29
     * @Param []
     * @return java.util.Map<java.lang.String,java.lang.Integer>
     **/
    @RequestMapping("/station_static_pie")
    @ResponseBody
    public Map<String,Integer> station_static_pie(){
        Map<String,Integer> map = new HashMap<>();
        num ++;
        map.put("posts",num+29);
        map.put("noPosts",num+9);

        map.put("deal",num+38);
        map.put("noDeal",num+41);

        map.put("finished",num+79);
        map.put("noFinished",num+59);
        return map;
    }



    /**
     * @Author 何平 
     * @Description  返回部门好评率
     * @Date 18:49 2018/7/29
     * @Param []
     * @return java.util.Map<java.lang.String,java.lang.Integer>
     **/
    @RequestMapping("/depart_static_good")
    @ResponseBody
    public Map<String,Integer> depart_static_good(){
        Map<String,Integer> map = new HashMap<>();
        num ++;
        map.put("good",num+48);
        map.put("noGood",num+24);
        return map;
    }
}
